package output;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Scanner;

import organization.Base;
import person.Admin;
import person.PersonInfo;
	public class AdmConsole extends Console {
	

	private SimpleDateFormat format3 = new SimpleDateFormat("dd.MM.yyyy");
	private Admin adm=new Admin();
	
	public AdmConsole (){
		if (consoleStr.size() == 0) {
			consoleStr.add("Get all Administration Personal List;");
			consoleStr.add("Add new Administration Personal;");
			consoleStr.add("Get all info by name;");
			consoleStr.add("Set Job for Personal;");
			consoleStr.add("Return to main menu.");
		}
	}
	@Override	
	public void inputInConsole() {
		int opt;
		Scanner scan = new Scanner(System.in);
		System.out.println("Please enter option:");
		while (true) {
			while (scan.hasNextLine()) {
				if (scan.hasNextInt()) {
					opt = scan.nextInt();
					if (opt == 1) {
						printAdmPersonal();
						getConsole();
						return;
					}
					if (opt == 2) {
						AddAdmPersonal(AddPersonal());
						getConsole();
						return;
					}
					if (opt == 3) {
						infoByName();
						getConsole();
						return;
					}
					if (opt == 4) {
						setJob();
						getConsole();
						return;
					}
					if (opt == 5) {
						return;
					}
					System.out.println("Admin Personal Menu \r\n__________________________\r\nPlease enter option:");
				} else {
					System.out.println("Should be numeric! Please enter option:");
					scan.next();
				}
			}
		}
	}
	
	private void printAdmPersonal (){
		ArrayList <Admin> admList = Base.getSortlist(adm);
		if (admList.size()>0){
			for (int i=0; i<admList.size();i++){
				System.out.println((i+1)+". Name:"+admList.get(i).getFirstAndScndName()+". Job:"+admList.get(i).getJob());
			}	
		}else{
			System.out.println("No Administration Personal was found!");
		}
	}
	private void AddAdmPersonal (PersonInfo person){
		if (person != null) {
			Base.addPerson(new Admin(person));
		}
	}

	private Admin infoByName (){
		ArrayList <Admin> admList = Base.getSortlist(adm);
		Scanner scan =  new Scanner (System.in);
		System.out.println("Pelase enter Fist name:");
		String frstName = scan.next();
		System.out.println("Please enter Second name:");
		String scndName = scan.next();
		
		Admin parsedAdmin = Base.getPersonByName(frstName, scndName, adm);
		if (parsedAdmin != null){
			
			System.out.println("Job is "+parsedAdmin.getJob()+".Born "+parsedAdmin.getPlaceOfBirth()+" "+format3.format(parsedAdmin.getBirth().getTime()));
			
		}
		
		return parsedAdmin;
		
		
	}
	private void setJob (){
		Scanner scan = new Scanner (System.in);
		Admin inputObj = infoByName();
		if (inputObj != null){
			System.out.println("Please enter Job:");
			inputObj.setJob(scan.nextLine());
		}else{
			System.out.println("Person not found. Please try again.");
			setJob();
			return;
		}
	}
}
